package com.flyaudio.xiaopengautopilot.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.flyaudio.xiaopengautopilot.R;
import com.flyaudio.xiaopengautopilot.util.DataInfo;
import com.flyaudio.xiaopengautopilot.constant.ModuleKey;

public class TpmsDialog extends Dialog {

    private Context context;
    private int resLayout;

    private TextView vehicle_tpms_lf, vehicle_tpms_temp_lf;
    private TextView vehicle_tpms_rf, vehicle_tpms_temp_rf;
    private TextView vehicle_tpms_lr, vehicle_tpms_temp_lr;
    private TextView vehicle_tpms_rr, vehicle_tpms_temp_rr;

    public TpmsDialog(Context context) {
        super(context);
    }

    public TpmsDialog(Context context, int themeResId) {
        super(context, themeResId);
    }

    public TpmsDialog(Context context, int theme, int resLayout) {
        super(context, theme);
        this.context = context;
        this.resLayout = resLayout;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(resLayout);

        Window dialogWindow = getWindow();
        WindowManager manager = ((Activity) context).getWindowManager();
        WindowManager.LayoutParams params = dialogWindow.getAttributes();
        dialogWindow.setGravity(Gravity.BOTTOM);

        initView();
        updateView();
    }

    private void initView() {
        vehicle_tpms_lf = findViewById(R.id.vehicle_tpms_lf);
        vehicle_tpms_temp_lf = findViewById(R.id.vehicle_tpms_temp_lf);
        vehicle_tpms_rf = findViewById(R.id.vehicle_tpms_rf);
        vehicle_tpms_temp_rf = findViewById(R.id.vehicle_tpms_temp_rf);
        vehicle_tpms_lr = findViewById(R.id.vehicle_tpms_lr);
        vehicle_tpms_temp_lr = findViewById(R.id.vehicle_tpms_temp_lr);
        vehicle_tpms_rr = findViewById(R.id.vehicle_tpms_rr);
        vehicle_tpms_temp_rr = findViewById(R.id.vehicle_tpms_temp_rr);
    }

    private void updateView() {
        double val_vehicle_tpms_lf= 0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_LF) != null) {
            val_vehicle_tpms_lf = (double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_LF);
        }
        double  val_vehicle_tpms_rf=0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_RF) != null) {
            val_vehicle_tpms_rf=(double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_RF);
        }

        double val_vehicle_tpms_lr=0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_LR) != null) {
            val_vehicle_tpms_lr=(double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_LR);
        }
        double val_vehicle_tpms_rr=0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_RR) != null) {
            val_vehicle_tpms_rr=(double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_RR);
        }
        double  val_vehicle_tpms_temp_lf=0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_DOUBLEVEHICLE_TPMS_TEMP_LF) != null) {
            val_vehicle_tpms_temp_lf=(double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_DOUBLEVEHICLE_TPMS_TEMP_LF);
        }
        double val_vehicle_tpms_temp_rf= 0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_TEMP_RF) != null) {
            val_vehicle_tpms_temp_rf=(double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_TEMP_RF);
        }
        double val_vehicle_tpms_temp_lr= 0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_TEMP_LR) != null) {
            val_vehicle_tpms_temp_lr=(double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.TPMS_VEHICLE_TPMS_TEMP_LR);
        }
        double val_vehicle_tpms_temp_rr= 0.0;
        if(DataInfo.getInstance().getDataParamerInfo(ModuleKey.VTPMS_EHICLE_TPMS_TEMP_RR) != null) {
            val_vehicle_tpms_temp_rr=(double) DataInfo.getInstance().getDataParamerInfo(ModuleKey.VTPMS_EHICLE_TPMS_TEMP_RR);
        }
        vehicle_tpms_lf.setText(String.format(context.getResources().getString(R.string.vehicle_tpms), val_vehicle_tpms_lf));
        vehicle_tpms_rf.setText(String.format(context.getResources().getString(R.string.vehicle_tpms), val_vehicle_tpms_rf));
        vehicle_tpms_lr.setText(String.format(context.getResources().getString(R.string.vehicle_tpms), val_vehicle_tpms_lr));
        vehicle_tpms_rr.setText(String.format(context.getResources().getString(R.string.vehicle_tpms), val_vehicle_tpms_rr));

        vehicle_tpms_temp_lf.setText(String.format(context.getResources().getString(R.string.vehicle_tpms_temp), val_vehicle_tpms_temp_lf));
        vehicle_tpms_temp_rf.setText(String.format(context.getResources().getString(R.string.vehicle_tpms_temp), val_vehicle_tpms_temp_rf));
        vehicle_tpms_temp_lr.setText(String.format(context.getResources().getString(R.string.vehicle_tpms_temp), val_vehicle_tpms_temp_lr));
        vehicle_tpms_temp_rr.setText(String.format(context.getResources().getString(R.string.vehicle_tpms_temp), val_vehicle_tpms_temp_rr));
    }

}
